package program.TokenAndParser;

import java.util.ArrayList;

public class Tokenizer {

	public ArrayList<Token> tokenize(String command) {
		char[] charlist = command.toCharArray();
		ArrayList<Token> tokenlist = new ArrayList<Token>();
		int counter = 0;
		while (counter < charlist.length) {
			if (charlist[counter] == '(') {
				tokenlist.add(new Token(charlist, counter, counter));
				counter++;
			} else if (charlist[counter] == ')') {
				tokenlist.add(new Token(charlist, counter, counter));
				counter++;
			} else if (Character.isWhitespace(charlist[counter])) {
				counter++; 
			} else {
				int from = counter;
				while (!Character.isWhitespace(charlist[counter]) && (charlist[counter] != '(') && (charlist[counter] != ')')) {
					counter++; // zolang het geen spatie is, hoog de counter op
								// (tijdens inlezen woord)
				}
				tokenlist.add(new Token(charlist, from, counter - 1));
			}
		}
		return tokenlist;
	}
}
